//
//  LoginInfoTool.m
//  掌上宏力
//
//  Created by admin on 2017/4/16.
//  Copyright © 2017年 admin. All rights reserved.
//

#import "LoginInfoTool.h"

#define kFilePath @"loginInfo.data"
#define kLoginInfoPath [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0] stringByAppendingPathComponent:kFilePath]


@implementation LoginInfoTool
singleton_implementation(LoginInfoTool)

-(instancetype)init{
    if (self = [super init]) {
        _currentUser = [NSKeyedUnarchiver unarchiveObjectWithFile:kLoginInfoPath];
       
    }
    return self;
   
}

-(void)setCurrentUser:(User *)currentUser{
    //设置当前登录用户信息
    _currentUser = currentUser;
    //归档
    [NSKeyedArchiver archiveRootObject:_currentUser toFile:kLoginInfoPath];
}

-(void)clearLoginInfo{
    _currentUser = nil;
    NSFileManager *fileManager = [[NSFileManager alloc] init];
    [fileManager removeItemAtPath:kLoginInfoPath error:nil];
}


@end
